/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Controller;

import Modele.Contact;
import Modele.FileManipulation;
import Modele.GetGroup;
import Modele.GetGroupContact;
import Modele.Group;
import Vue.Window;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.JTextField;

/**
 *this Listener delete the contact in the accurateView from the database
 * @author Bakalian
 */
public class DeleteContactListener implements MouseListener{
    
    private Window myRootWindow;
    private int idNumber;
    private List<Contact> listofContact;
    private List<Group> listofGroup;

    public DeleteContactListener(Window w){
        myRootWindow=w;
        
    }
    
    @Override
    public void mouseClicked(MouseEvent e) {
        
        listofContact=myRootWindow.getMyListofContact();
        idNumber=myRootWindow.getMyContactPanel().getIdNumber();
        for(int i=0;i<listofContact.size();i++){
            if(Integer.parseInt(listofContact.get(i).getIdNumber())==idNumber){
                listofContact.remove(i);
                 FileManipulation fm=new FileManipulation();
                 fm.DeleteContact(listofContact);
                 myRootWindow.setMyListofContact(listofContact);
            }
        }
        GetGroupContact ggc=new GetGroupContact();
        GetGroup gg=new GetGroup();
        listofGroup=gg.getGroups();
        for(int j=1;j<listofGroup.size();j++){
            ggc.DeleteContactGroup(listofGroup.get(j).getNamegroup(), idNumber);
        }
        
        
        
        /*
        
        FileManipulation fm=new FileManipulation();
        List<Contact> listofContact=fm.getContact();
                System.out.println();
                int idnumber=Integer.parseInt(listofContact.get(this.avl.getSelectedRow()).getIdNumber());
                listofContact.remove(this.avl.getSelectedRow());
                for(int i=0;i<listofContact.size();i++){
                    int nea=i+1;
                    String str=String.valueOf(nea);
                    listofContact.get(i).setIdNumber(str);
                }
                
                
                
                GetGroupContact ggc=new GetGroupContact();
                GetGroup gg=new GetGroup();
                List<Group> listgroups=gg.getGroups();
                
                for(int j=0;j<listgroups.size();j++){
                    
                    ggc.DeleteContactGroup(listgroups.get(j).getNamegroup(), idnumber);
                }
                
               
               
               
               
                
                fm.DeleteContact(listofContact);
    
                */}

    @Override
    public void mousePressed(MouseEvent e) {
       // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
